#pragma once

#include "PointLabCore/Entity.h"

#include <QAbstractItemModel>
#include <QTreeView>

#include <osg/ref_ptr>
#include <osg/Node>

class TreeModel :public QAbstractItemModel
{
	Q_OBJECT
public:
	TreeModel(QTreeView* view, QObject* parent);
	virtual ~TreeModel();

	void setRootNode(osg::Node *node);
	osg::Node* getRootNode();

	void addElement(osg::Node* node, bool autoExpand = true);
	void removeElement(osg::Node* node);

	virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
	virtual QModelIndex index(osg::Node* node);

	virtual QModelIndex parent(const QModelIndex &child) const override;

	virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
	virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;

	virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
	virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;

	virtual Qt::ItemFlags flags(const QModelIndex &index) const override;

	void changeSelection(const QItemSelection & selected, const QItemSelection & deselected);

	PointLabCore::Uint getSelectedEntities(std::vector<osg::Node*>& selectedEntities);
signals:
	void selectionChanged();

private:
	osg::ref_ptr<osg::Node> mRootNode;
	QTreeView* mdbTreeWidget;
};
